<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set var="ctxPath" value="${pageContext.request.contextPath}"/>

<!DOCTYPE html>
<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
   <meta name="renderer" content="webkit">
   <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
   <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
   <link rel="stylesheet" href="${ctxPath}/static/layui/css/layui.css" />
   <title>添加公告</title>
   <script src="${ctxPath}/static/layui/layui.js" charset="utf-8"></script>
   <script src="${ctxPath}/static/js/jquery-3.6.1.min.js"></script>
    <script src="${ctxPath}/static/js/jquery.form.min.js"></script>
</head>
<body>
	<fieldset class="layui-elem-field layui-field-title"
		style="margin-top: 20px;">
	    <legend>添加公告</legend>
	</fieldset>

   <form  class="layui-form"  id="xiaojie"
	     action="${ctxPath}/Notify/saveNotify" method="POST"
	     enctype="multipart/form-data">


 	<div class="layui-form-item">
    	 <label class="layui-form-label">通告标题</label>
		 <div class="layui-input-block" style="width:450px;">
			<input type="text" id="notifyName"
				name="notifyName" autocomplete="off"
				placeholder="请输入通告标题"
				class="layui-input">
		  </div>
   	  </div>

  <div class="layui-form-item">
    	 <label class="layui-form-label">备注内容</label>
		 <div class="layui-input-block" style="width:450px;">
			<input type="text" id="note"
				name="note" autocomplete="off"
				placeholder="请输入备注内容"
				class="layui-input">
		  </div>
   	  </div>


   	   <div class="layui-form-item">
    	 <label class="layui-form-label">上传附件</label>
		 <div class="layui-input-block">
			<input type="file" name="pdfFile" style="height:50px;">
		  </div>
   	  </div>



	  <div class="layui-form-item">
    	<div class="layui-input-block">
		    <input type="submit" class="layui-btn" value="立即提交">
    		<button type="reset" class="layui-btn layui-btn-primary"
    		onclick="reloadPage1();">重置</button>
	    </div>
   	  </div>
   </form>

<script>
layui.use(
	['form', 'layedit', 'laydate'],
	function(){
		var form = layui.form;
		var layer = layui.layer;
		console.log('{DEBUG} layui.user...');
	}
);

/*
$('#xiaojie').ajaxForm(function (resp) {
    layer.msg("公告发布成功。");
});
*/


window.onload = function(){
	var ret = "${param['result']}";
	console.log(ret)
	var msg = "${param['msg']}";
	if( ret=='success' ){
		layer.msg('上传成功.');
		setTimeout(reloadPage,2000);
	}else if( ret=='failed' ){
		layer.msg('上传失败, 原因:'+ msg);
	}
}

function reloadPage(){
	window.location = "${ctxPath}/Notify/viewList";
}
function reloadPage1(){
	window.location = "${ctxPath}/Notify/viewAdd";
}

$('#xiaojie').ajaxForm({
	dataType: 'json',
	success: function (resp) {
		let result = resp['result'];
		if (result === "success") {
			let data = resp['data'];
			layer.msg(data);
			setTimeout(reloadPage, 2000);
		} else {
			let cause = resp['cause']
			layer.msg(cause);
		}
	}
});


</script>
</body>
</html>